package cn.itcast.myapplication.room;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

  /**
   *
   *   数据库的增删改查都要在这里声明
   *
   * */

@Dao
public interface WordDao {

    //数据库的增删改查都要在这里声明
    @Insert
    void insertWords(Word...words);//插入数据 ...words表示插入多条数据

    @Update
    void updateWords(Word...words);//修改数据 ...words表示插入多条数据

    @Delete
    void deleteWords(Word...words);//删除数据 ...words表示插入多条数据

    @Query("DELETE FROM WORD")

    void deleteAllWords();//删除所有数据

    @Query("SELECT * FROM WORD ORDER BY ID DESC")

    LiveData<List<Word>> getAllWords();//获取所有数据

    @Query("SELECT * FROM WORD WHERE english_word LIKE:patten ORDER BY ID DESC ")//筛选要查询的数据

    LiveData<List<Word>> findWordsWithPatten(String patten);

   }

